<!--
  * 地址对照
-->
<template>
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">     
     <a-form-item label="楼栋全称" class="smart-query-form-itme" name="buildingName">
        <a-input style="width: 300px" v-model:value="queryForm.buildingName" placeholder="请输入楼栋全称" />
      </a-form-item>

      <a-form-item label="门牌号" class="smart-query-form-itme smart-margin-left10" name="buildingAddr">
        <a-input style="width: 200px" v-model:value="queryForm.buildingAddr" placeholder="请输入门牌号" />
      </a-form-item>
      <a-form-item label="楼栋号" class="smart-query-form-itme smart-margin-left10" name="buildingNum">
        <a-input style="width: 120px" v-model:value="queryForm.buildingNum" placeholder="请输入证载地址" />
      </a-form-item>
      <a-form-item label="房号" class="smart-query-form-itme smart-margin-left10" name="houseNumber">
        <a-input style="width: 120px" v-model:value="queryForm.houseNumber" placeholder="请输入房号" />
      </a-form-item>
      <a-form-item label="城市" class="smart-query-form-itme smart-margin-left10" name="cityCode">
        <DictSelectType ref="dictSelectType" :service-id="SERVICE_ID_ENUM.DICTIONARY.value" :dcit-type="DICT_TYPE_ENUM.CITY_SELECT.value" :width="'120px'"  :height="400" v-model:value="queryForm.cityCode" />
      </a-form-item>

      <a-form-item class="smart-query-form-item smart-margin-left10">
        <a-button type="primary" @click="ajaxQuery">
          <template #icon>
            <SearchOutlined />
          </template>
          查询
        </a-button>
        <a-button @click="resetQuery">
          <template #icon>
            <ReloadOutlined />
          </template>
          重置
        </a-button>
        <a-button class="smart-margin-left20" @click="moreQueryConditionFlag = !moreQueryConditionFlag">
            <template #icon>
              <MoreOutlined />
            </template>
            {{ moreQueryConditionFlag ? '收起' : '展开' }}
          </a-button>
      </a-form-item>
    </a-row>

    <a-row class="smart-query-form-row" v-show="moreQueryConditionFlag">
      <a-form-item label="证载地址" class="smart-query-form-itme" name="certAddress">
        <a-input style="width: 300px" v-model:value="queryForm.certAddress" placeholder="请输入证载地址" />
      </a-form-item>

      <a-form-item label="行政区" class="smart-query-form-itme" name="districtName">
        <a-input style="width: 200px" v-model:value="queryForm.districtName" placeholder="请输入行政区" />
      </a-form-item>

      <a-form-item label="楼盘" class="smart-query-form-itme" name="communityName">
        <a-input style="width: 200px" v-model:value="queryForm.communityName" placeholder="请输入楼盘名称" />
      </a-form-item>

      <a-form-item label="单元号" class="smart-query-form-itme" name="unitNum">
        <a-input style="width: 200px" v-model:value="queryForm.unitNum" placeholder="请输入单元号" />
      </a-form-item>
      </a-row>
  </a-form>

  <a-card size="small" :bordered="false" :hoverable="true">
    <a-table
      :scroll="{ x: 1300 }"
      size="small"
      :dataSource="tableData"
      :columns="columns"
      rowKey="house_code"
      :pagination="false"
      :loading="tableLoading"
      bordered
    >
    </a-table>

    <div class="smart-query-table-page">
      <a-pagination
        showSizeChanger
        showQuickJumper
        show-less-items
        :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="queryForm.pageSize"
        v-model:current="queryForm.pageIndex"
        v-model:pageSize="queryForm.pageSize"
        :total="total"
        @change="ajaxQuery"
        @showSizeChange="ajaxQuery"
        :show-total="(total) => `共${total}条`"
      />
    </div>
  </a-card>
  <CheckCity ref="checkCityRef" />
</template>

<script setup lang="ts">
  import { reactive, ref, onMounted,computed } from 'vue';
  import { asApi } from '/@/api/addrstandard/as-api'
  import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '/@/constants/common-const';
  import { smartSentry } from '/@/lib/smart-sentry';
  import DictSelectType from '/@/components/cache/dict-select-type.vue'
  import { SERVICE_ID_ENUM,DICT_TYPE_ENUM } from '/@/constants/system/cache-service-id-const';

  // --------------------------- 企业表格 列 ---------------------------

  const columns = ref([
    {
      title: '证载地址',
      dataIndex: 'certAddress',
      minWidth: 180,
      // ellipsis: true,
    },
    {
      title: '楼盘名称',
      dataIndex: 'communityName',
      width: 180,
      ellipsis: true,
    },
    {
      title: '楼栋地址',
      dataIndex: 'buildingAddr',
      width: 180,
      ellipsis: true,
    },
    {
      title: '楼栋全称',
      dataIndex: 'buildingName',
      width: 180,
    },
    {
      title: '幢/栋',
      dataIndex: 'buildingNum',
      width: 80,
    },
    {
      title: '单元/梯/座',
      dataIndex: 'unitNum',
      width: 100,
    },
    {
      title: '房号',
      width: 80,
      dataIndex: 'houseNumber',
      ellipsis: true,
    },
    {
      title: '省',
      width: 80,
      dataIndex: 'proviceName',
      ellipsis: true,
    },
    {
      title: '城市',
      width: 80,
      dataIndex: 'cityName',
      ellipsis: true,
    },
    {
      title: '区',
      dataIndex: 'districtName',
      fixed: 'right',
      width: 80,
    },
  ]);

  // --------------------------- 查询 ---------------------------

  const queryFormState = {
    certAddress: undefined,
    communityName: undefined,
    buildingName: undefined,
    buildingAddr: undefined,
    cityCode: undefined,
    buildingNum: undefined,
    unitNum: undefined,
    houseNumber: undefined,
    districtName: undefined,
    pageIndex: 1,
    pageSize: PAGE_SIZE,
  };
  const queryForm = reactive({ ...queryFormState });
  const tableLoading = ref(false);
  const tableData = ref([]);
  const total = ref(0);
  const moreQueryConditionFlag = ref(true);

  function resetQuery() {
    Object.assign(queryForm, queryFormState);
    ajaxQuery();
  }

  async function ajaxQuery() {
    try {
      tableLoading.value = true;
      let responseModel = await asApi.searchLookupPage(queryForm);
      total.value = responseModel.data.total;
      tableData.value = responseModel.data.data;
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      tableLoading.value = false;
    }
  }
</script>
